//
//  LYBackView.m
//  SZBank
//
//  Created by LuoYao on 16/7/14.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "LYBackView.h"

@interface LYBackView ()

@end
@implementation LYBackView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _cKwidth = frame.size.width;
        _cKheight = frame.size.height;
    
        self.backgroundColor = [UIColor colorWithRed:0.0034 green:0.0034 blue:0.0034 alpha:0.6];
        
    }
    return self;
}


- (void)dismissAnimation{
    [UIView animateWithDuration:0.5 animations:^{
        self.subviews.firstObject.center = CGPointMake(self.center.x, _cKheight + _cKheight / 2);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        self.subviews.firstObject.center = CGPointMake(_cKwidth * 0.5, _cKheight * 0.5);
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //获取在视图上的点击区域
    CGPoint touchPoint = [[touches anyObject] locationInView:self];
    CGRect rect = CGRectMake(_cKwidth * 0.2, _cKheight * 0.2, _cKwidth * 0.6, _cKheight * 0.2);
    if (self.subviews.firstObject) {
        rect = self.subviews.firstObject.frame;
    }
    
    
    //判断包含
    if (!CGRectContainsPoint(rect, touchPoint)) {
        [self dismissAnimation];
    }
}


@end
